/* Copyright 2017, 2018, Gabriel Czernikier
 *
 * This file is part of Notehaus.
 * Notehaus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * Notehaus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Notehaus.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include<zlib.h>
#include "adler32.h"
// An Adler32 produced from a list of struct size_data.
uint32_t adler32_data(struct list_head *chunks_start, struct list_head *chunks_end) {
  uLong adler = adler32(0L, Z_NULL, 0);
  struct list_head *tmp;
  struct size_data *sd;
  range_for_each(tmp, chunks_start, chunks_end) {
    sd = list_entry(tmp, struct size_data, size_data_list);
    adler = adler32(adler, (unsigned char*)sd->data, sd->size);
  }
  return (uint32_t)adler;
}

// The size of an Adler32 number.
size_t adler32_size() {
  return sizeof(uint32_t);
}
